/*
 * worker.h
 *
 *  Project Name: ratbox-monitor
 *    Created on: Dec 1, 2010
 *        Author: Daniel J Reidy <dubkat@ratbox.org>
 *            Id: $Id: worker.h 8 2011-09-14 03:59:20Z dubkat $
 */

#ifndef WORKER_H_
#define WORKER_H_

#include <netinet/in.h>
#include "common.h"
#include "uthash.h"
#include "rb_patricia.h"

// this describes each client
struct my_clients
{
	// XXX get appropriate defines for these.
	unsigned int id;	/* we'll use this field as the key */
	int isSpoofed;		/* used for spoofed-user immunity */
	int isOper;
	int isAdmin;
	int seed;
	int isBanned;
	char class[20];
	char ip[INET6_ADDRSTRLEN];
	char nick[12];
	char user[12];
	char host[255];
	char extra1[20];
	char extra2[20];
	char gecos[100];

	UT_hash_handle hh;	/* makes this structure hashable */
};

// parv[3](O) parv[4](nyt@rznt.com) parv[5](*) parv[6](nyt)
struct my_opers
{
	unsigned int id;
	char opernick[12];
	char operhost[255];
	int admin;

	UT_hash_handle hh;
};

enum
{
	STOP,
	START,
};

enum
{
	BAN_SEED,
	BAN_FLOOD,
	BAN_JUPE,
	BAN_HAMMER,
};

enum
{
	INVALID = -1,
	KILL = 0,
	KLINE = 1,
	XLINE = 2,
	DLINE = 3,


};




int seedscore(const char *);	// from seedrand.c

unsigned int new_id(int);
void sendto_one(struct conn *serv, const char *format, ...);
char *elapse(int);
void report_to_channel(struct conn *, const char *, ...);
void join_channels(struct conn *serv);
void send_queued(struct conn *serv);
int time_diff(struct timeval *, struct timeval *, struct timeval *);
void hash_add_oper(struct my_opers *);
void hash_add_client(struct my_clients *);
void hash_del_client(struct my_clients *);
int check_seedscore(const struct my_clients *);
int ban_client(struct conn *, struct my_clients *, int);
void qname_from_url(const char *, char *);
void userhost_from_nuh(const char *, char *);
unsigned int hash_count_clients_by_userhost(const char *, const char *);
unsigned int hash_count_clients_by_user(const char *);
unsigned int hash_count_clients_by_host(const char *);
unsigned int hash_count_clients_by_ip(const char *);


/* ripped straight from ircd-ratbox match.h */

/*
 * irccmp - case insensitive comparison of s1 and s2
 */
int irccmp(const char *s1, const char *s2);
/*
 * ircncmp - counted case insensitive comparison of s1 and s2
 */
int ircncmp(const char *s1, const char *s2, int n);


/*
 * character macros
 */
extern const unsigned char ToLowerTab[];
#define ToLower(c) (ToLowerTab[(unsigned char)(c)])

extern const unsigned char ToUpperTab[];
#define ToUpper(c) (ToUpperTab[(unsigned char)(c)])




#endif /* WORKER_H_ */
